<template>
  <div class="ada-notice">
    <div>
      <span class="titleSty">未审理</span>
    </div>
    <div class="homeworkList">
      <el-table
          :data="tableData.filter(data => !search || data.title.toLowerCase().includes(search.toLowerCase()))"
          style="width: 100%;"
          height="12.5rem">
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-form label-position="left" inline class="demo-table-expand">
                <el-form-item label="内容：">
                  <span>{{ props.row.content }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column
          label="日期"
          sortable
          prop="update_date">
          </el-table-column>
          <el-table-column
          label="科目"
          prop="subject_name">
          </el-table-column>
          <el-table-column
          align="right">
          <template slot-scope="scope">
            <el-button
            size="mini"
            style="background-color: #66cccc;float:left;"
            @click="toCheck(scope.row)">审阅</el-button>
          </template>
          </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import http from '../../../util/http';

export default {
  name: 'refresh',
  inject: ['reload'],
  data() {
    return {
      tableData: [],
      search: '',
    };
  },
  methods: {
    getNoticeList() {
      http.get(`/questionAPI/getListByUnCheck?sid=${window.localStorage.getItem('userId')}`)
      .then((res) => {
        this.tableData = res.resultMap.unCheckList;
      })
      .catch((error) => {
        console.log(error);
      });
    },
    toCheck(row) {
      window.localStorage.setItem('questionId', row.id);
        this.$confirm('是否审阅此条通知信息?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          http.put(`/questionAPI/updateCheckFlag?id=${window.localStorage.getItem('questionId')}`)
          .then((res) => {
            this.refresh();
          })
          .catch((error) => {
            console.log(error);
          });
          this.$message({
            type: 'success',
            showClose: true,
            message: '审阅成功!',
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            showClose: true,
            message: '已取消审阅',
          });
        });
    },
    refresh() {
      this.reload();
    },
  },
  mounted() {
    this.getNoticeList();
  },
};
</script>
<style scoped>
.ada-notice{
  margin: 0 2.5rem 0 0;
  width: 13rem;
}
.titleSty{
  color: white;
  font-size: .7rem;
  margin: 0 0 0 .5rem;
}
.homeworkList{
  box-shadow:.1rem .06rem .15rem #888;
  margin-top: .5rem;
}
.demo-table-expand .el-form-item {
  margin: 0;
  width: 90%;
}
</style>
